import QtQuick 2.11
//import QtQuick.Controls 1.4
import QtQuick.Controls 2.2
import QtGraphicalEffects 1.0

import "."
import "_Global"
import "_Global/Button"

import "_Global/Global.js" as GlobalJS
import "GameJS.js" as GameJS

Rectangle {
    property int sex: -1
    signal s_RegGameUserInfo(var param) //nickName,sex
    //signal s_Close()

    function showErr(msg) {
        errLabel.text = msg;
    }

    id: root
    anchors.fill: parent
    //color: "white"
    //width: 602
    //height: 390

    Image { //背景
        id: backImage
        source: Global.resource.images.gameRegGame.back
        anchors.fill: parent
    }


    /*Text {
        x: Global.dpW(805)
        y: Global.dpH(570)
        width: Global.dpW(250)
        height: Global.dpH(87)
        text: qsTr("游戏名")
        font.pixelSize: Global.dpH(12)
        visible: false
    }*/

    TextField {
        id: nickName
        x: Global.gamePos.mapRegGameUser.rectName.x
        y: Global.gamePos.mapRegGameUser.rectName.y
        width: Global.gamePos.mapRegGameUser.rectName.width
        height: Global.gamePos.mapRegGameUser.rectName.height
        text: qsTr("")
        //font.family: ""
        font.pixelSize: Global.gamePos.mapRegGameUser.nNameFontSize
        validator: RegExpValidator {
            //regExp: /^\S{2,8}/;     ///^[^\s]{2,8}/;    //中文也占1个位置
            //regExp: /[\x4E00-\x9FA5]+/;
            regExp: /^[A-Za-z0-9\x4e00-\x9fa5]{2,16}$/
        }
        //maximumLength: 8
        selectByMouse: true
        placeholderText: "请注册游戏名称"
        color: "white"
        background: Rectangle {
            //color: control.enabled ? "transparent" : "#353637"
            //border.color: control.enabled ? "#21be2b" : "transparent"
            color: "transparent"
        }
        //verticalAlignment: Text.AlignVCenter
        //horizontalAlignment: Text.AlignHCenter
        /*style: TextFieldStyle {
            textColor: "white"
            placeholderTextColor: "gray"
            background: Rectangle {
                color: "#00000000"
                //radius: 2
                //implicitWidth: 100
                //implicitHeight: 24
                //border.color: "#333"
                //border.width: 1
            }
        }*/
    }

    ImageButton2 {
        id: buttonStart        //开始游戏
        x: Global.gamePos.mapRegGameUser.rectStart.x
        y: Global.gamePos.mapRegGameUser.rectStart.y
        width: Global.gamePos.mapRegGameUser.rectStart.width
        height: Global.gamePos.mapRegGameUser.rectStart.height
        source: Global._FixResourcePath_R("Media/Images/RegGame/Start.png")

        soundEffectClick: Global.resource.effects.effectButton
        bEffectOn: Global.config.bEffectOn

        onButtonClicked: {
            /*
            if(GlobalJS.strlen(nickName.text) < 4) {
                showErr("昵称长度不够");
                console.debug(nickName.text.length);
                return;
            }
            else if(GlobalJS.strlen(nickName.text) > 16) {
                showErr("昵称长度过长");
                console.debug(nickName.text.length);
                return;
            }

            if(nickName.text.length < 2 || nickName.text.length > 16) {
                showErr("长度必须在4到16个汉字，字母或数字之间");
                return;
            }*/

            if(root.sex != 1 && root.sex != 0) {
                showErr("请选择性别");
                //console.debug(root.sex);
                return;
            }

            var paramObj = new Object;
            //paramObj.userName = userName.text
            paramObj.nickName = nickName.text
            //paramObj.passwordMd5 = Qt.md5(password.text)
            paramObj.sex = root.sex;
            s_RegGameUserInfo(paramObj);
            //console.debug(paramObj,paramObj.sex,paramObj.passwordMd5)
        }
    }

    Item {
        id: boy
        x: Global.gamePos.mapRegGameUser.rectBoy.x
        y: Global.gamePos.mapRegGameUser.rectBoy.y
        width: Global.gamePos.mapRegGameUser.rectBoy.width
        height: Global.gamePos.mapRegGameUser.rectBoy.height

        Image {
            id: imageBoy
            source: Global._FixResourcePath_R("Media/Images/RegGame/Boy.png")
            anchors.fill: parent
        }
        MouseArea {
            anchors.fill: parent
            onClicked: {
                root.sex = 1;
            }
        }

        RectangularGlow {
            id: boyGlow
            visible: root.sex == 1
            anchors.fill: boy
            glowRadius: 7  //边框宽度
            spread: 0.4    //虚化程度(0~1)
            color: "lightgreen"  //颜色
            z: -1
            //cornerRadius: rect.radius + glowRadius
        }
    }

    Item {
        id: girl
        x: Global.gamePos.mapRegGameUser.rectGirl.x
        y: Global.gamePos.mapRegGameUser.rectGirl.y
        width: Global.gamePos.mapRegGameUser.rectGirl.width
        height: Global.gamePos.mapRegGameUser.rectGirl.height

        Image {
            id: imageGirl
            source: Global._FixResourcePath_R("Media/Images/RegGame/Girl.png")
            anchors.fill: parent
        }
        MouseArea {
            anchors.fill: parent
            onClicked: {
                root.sex = 0;
            }
        }

        RectangularGlow {
            id: girlGlow
            visible: root.sex == 0
            anchors.fill: girl
            glowRadius: 7  //边框宽度
            spread: 0.4    //虚化程度(0~1)
            color: "lightgreen"  //颜色
            z: -1
            //cornerRadius: rect.radius + glowRadius
        }
    }


    /*
    ExclusiveGroup {
        id: sex
        function getSex() {
            if(man.checked) return 1;
            else return 0;
        }
    }

    RadioButton {
        id: man
        x: 201
        y: 232
        text: qsTr("男")
        checked: true
        exclusiveGroup: sex
    }

    RadioButton {
        id: woman
        x: 314
        y: 232
        text: qsTr("女")
        exclusiveGroup: sex
    }
*/
    Label {
        id: errLabel
        x: Global.gamePos.mapRegGameUser.rectTextMsg.x
        y: Global.gamePos.mapRegGameUser.rectTextMsg.y
        width: Global.gamePos.mapRegGameUser.rectTextMsg.width
        height: Global.gamePos.mapRegGameUser.rectTextMsg.height
        font {
            //family: ""
            pixelSize: Global.gamePos.mapRegGameUser.nMsgFontSize
        }
        color: "black"
        horizontalAlignment: Label.AlignHCenter
        verticalAlignment: Label.AlignVCenter

        text: qsTr("")
    }

    Component.onCompleted: {
    }
}
